

use "$data/survey1_clean.dta", clear

gen experiment_2=1

append using "$data/survey2_clean.dta"
recode experiment_2  (.=0)




**** Summary stastistics of knowledge ****
gen empt=.
label var empt " "



gen perceptions =. 
label var perceptions "\textbf{Panel A: Economic Anxieties}"
gen agree_severe_total = inlist(impact_1 , 4,5)*100
label var agree_severe_total "\% agree: world severely affected by coronavirus"
gen agree_severe_US = inlist(impact_2 , 4,5)*100
label var agree_severe_US "\% agree: US severely affected by coronavirus"
label var agree_severe_US "\% agree: US severely affected by coronavirus"

gen high_worry_corona_econ = inlist(worry_corona_econ , 3,4)*100
label var high_worry_corona_econ "\% worried about US economy"
gen high_worry_perecon = inlist(worry_perecon , 3,4)*100
label var high_worry_perecon "\% worried about personal econ. situation"



tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 8

set obs 10
gen x = 1
gen y = 1

qui {
forval i = 1/`columns' {
	eststo col`i': reg x y
} 
}
loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear



foreach yvar of varlist perceptions empt agree_severe_total agree_severe_US  high_worry_corona_econ high_worry_perecon empt{

	sum `yvar' if experiment_2==0 , d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = `r(N)' : col3
	}
	sum `yvar' if experiment_2==1, d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col4
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col5

	cap: estadd loc thisstat`count' = `r(N)' : col6
	
	reg `yvar' experiment_2 ,r
		lincom experiment_2
	estadd loc thisstat`count' = string(`r(estimate)', "%9.2f"): col7
	test	experiment_2
	estadd loc thisstat`count' = string(`r(p)', "%9.3f"): col8
	/* Row Labels */
	}
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}



/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"


esttab col* using "$tables/comparison_time.tex", booktabs cells(none)  nogap mtitle("Mean" "SD"   "Obs."  "Mean" "SD" "Obs."  "$\Delta$" "p(early = late)") ///
 stats(`statnames', labels(`varlabels') )  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace ///
 mgroups("March 5" "March 16" "Comparison of means",  pattern(1 0 0  1 0  0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))


eststo clear
